package com.xy.cloud.feign.factory;

import com.xy.cloud.domain.R;
import com.xy.cloud.exception.BusinessException;
import com.xy.cloud.feign.BackStageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 文件服务降级处理
 *
 * @author ruoyi
 */
@Component
@Slf4j
public class BackStageFallbackFactory implements FallbackFactory<BackStageService> {

    @Override
    public BackStageService create(Throwable throwable) {
        log.error("服务调用失败:{}", throwable.getMessage());
        return new BackStageService() {

            @Override
            public R<?> get() {
                return R.fail("error-001");
            }

            @Override
            public R<?> save() {
                throw new BusinessException("保存异常 : " + throwable.getMessage());
            }
        };
    }
}
